<?php 
	/**
	 * [Excel 导出方法]
	 * @param int $type 类型判断导出哪种数据
	 * @param [string] $name [文件名]
	 * @param [array] $list [数据源]
	 * @author 蜗牛小分队
	 * case 6的方法为究极进化,理论可以通用
	 */
	function PHPExcel($type,$name,$list)
	{
		// 导入Excel类库
		import("Org.Util.PHPExcel");
		// 实例化
		$objPHPExcel = new \PHPExcel();
		// 设置Excel文件详细信息
		$objPHPExcel->getProperties()->setCreator("蜗牛小分队")
									 ->setLastModifiedBy("蜗牛小分队")
									 ->setTitle("Excel")
									 ->setSubject("Excel")
									 ->setDescription("Excel")
									 ->setKeywords("excel")
									 ->setCategory("file");

		switch ($type) {
			// 导出班级通讯录表格
			case 1:
				// 设置Excel单元格标题
				$objPHPExcel->setActiveSheetIndex(0)
							->setCellValue('A1', '姓名') 
							->setCellValue('B1', '手机') 
							->setCellValue('C1', '邮箱') 
							->setCellValue('D1', 'QQ');
				// 设置单元格宽度
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('A')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('B')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('C')
							->setWidth(25);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('D')
							->setWidth(20);
				foreach($list as $k => $v){
					$num = $k + 2;
					// 遍历数据放在单元格内
					$objPHPExcel->setActiveSheetIndex(0)
								->setCellValue('A'.$num, $v['name']) 
								->setCellValueExplicit('B'.$num, $v['phone'], PHPExcel_Cell_DataType::TYPE_STRING)
								->setCellValue('C'.$num, $v['email'])
								->setCellValueExplicit('D'.$num, $v['qq'], PHPExcel_Cell_DataType::TYPE_STRING);

					// 设置单元格左对齐
					$objPHPExcel->getActiveSheet()
								->getStyle('A'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('B'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('C'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('D'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
				 }
				break;
			// 导出班级保险数据
			case 2:
				// 设置Excel单元格标题
				$objPHPExcel->setActiveSheetIndex(0)
							->setCellValue('A1', '姓名') 
							->setCellValue('B1', '身份证号码');
				// 设置单元格宽度
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('A')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('B')
							->setWidth(30);
				foreach($list as $k => $v){
					$num = $k + 2;
					// 遍历数据放在单元格内
					$objPHPExcel->setActiveSheetIndex(0)
								->setCellValue('A'.$num, $v['name']) 
								->setCellValueExplicit('B'.$num, $v['card'], PHPExcel_Cell_DataType::TYPE_STRING);

					// 设置单元格左对齐
					$objPHPExcel->getActiveSheet()
								->getStyle('A'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('B'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
				 }
				break;
			// 导出班级绩效数据
			case 3:
				// 设置Excel单元格标题
				$objPHPExcel->setActiveSheetIndex(0)
							->setCellValue('A1', '姓名')
							->setCellValue('B1', '执行人')
							->setCellValue('C1', '扣分')
							->setCellValue('D1', '原因')
							->setCellValue('E1', '时间');
				// 设置单元格宽度
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('A')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('B')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('C')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('D')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('E')
							->setWidth(50);
				foreach($list as $k => $v){
					$num = $k + 2;
					// 遍历数据放在单元格内
					$objPHPExcel->setActiveSheetIndex(0)
								->setCellValue('A'.$num, $v['stu_id'])
								->setCellValue('B'.$num, $v['do_id'])
								->setCellValue('C'.$num, $v['score'])
								->setCellValue('D'.$num, $v['cause'])
								->setCellValue('E'.$num, $v['created']);
					// 设置单元格左对齐
					$objPHPExcel->getActiveSheet()
								->getStyle('A'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('B'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('C'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('D'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('E'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
				 }
				break;
			// 导出班级请假数据
			case 4:
				// 设置Excel单元格标题
				$objPHPExcel->setActiveSheetIndex(0)
							->setCellValue('A1', '姓名')
							->setCellValue('B1', '请假原因')
							->setCellValue('C1', '起始时间')
							->setCellValue('D1', '终止时间')
							->setCellValue('E1', '请假天数');
				// 设置单元格宽度
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('A')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('B')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('C')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('D')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('E')
							->setWidth(50);
				foreach($list as $k => $v){
					$num = $k + 2;
					// 遍历数据放在单元格内
					$objPHPExcel->setActiveSheetIndex(0)
								->setCellValue('A'.$num, $v['pid'])
								->setCellValue('B'.$num, $v['cause'])
								->setCellValue('C'.$num, $v['start_time'])
								->setCellValue('D'.$num, $v['end_time'])
								->setCellValue('E'.$num, $v['day']);

					// 设置单元格左对齐
					$objPHPExcel->getActiveSheet()
								->getStyle('A'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('B'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('C'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('D'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('E'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
				 }
				break;

				case 5:
				// 设置Excel单元格标题
				$objPHPExcel->setActiveSheetIndex(0)
							->setCellValue('A1', '姓名')
							->setCellValue('B1', '性别')
							->setCellValue('C1', '籍贯')
							->setCellValue('D1', '身份证号码')
							->setCellValue('E1', '小组')
							->setCellValue('F1', '绩效分')
							->setCellValue('G1', '手机')
							->setCellValue('H1', '邮箱')
							->setCellValue('I1', 'QQ')
							->setCellValue('J1', '学校所在省')
							->setCellValue('K1', '毕业院校')
							->setCellValue('L1', '专业')
							->setCellValue('M1', '学历')
							->setCellValue('N1', '计算机基础')
							->setCellValue('O1', '工作经验(年)')
							->setCellValue('P1', '目标薪资')
							->setCellValue('Q1', '紧急联系人')
							->setCellValue('R1', '与紧急联系人的关系')
							->setCellValue('S1', '紧急联系人手机');
				// 设置单元格宽度
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('A')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('B')
							->setWidth(10);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('C')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('D')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('E')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('F')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('G')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('H')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('I')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('J')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('K')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('L')
							->setWidth(30);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('M')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('N')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('O')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('P')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('Q')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('R')
							->setWidth(20);
				$objPHPExcel->getActiveSheet()
							->getColumnDimension('S')
							->setWidth(20);
								
				foreach($list as $k => $v){
					$num = $k + 2;
					// 遍历数据放在单元格内
					$objPHPExcel->setActiveSheetIndex(0)
								->setCellValue('A'.$num, $v['name'])
								->setCellValue('B'.$num, $v['sex'])
								->setCellValue('C'.$num, $v['address'])
								->setCellValueExplicit('D'.$num, $v['card'], PHPExcel_Cell_DataType::TYPE_STRING)
								->setCellValue('E'.$num, $v['team'])
								->setCellValue('F'.$num, $v['performance'])
								->setCellValue('G'.$num, $v['phone'])
								->setCellValue('H'.$num, $v['email'])
								->setCellValue('I'.$num, $v['qq'])
								->setCellValue('J'.$num, $v['school_address'])
								->setCellValue('K'.$num, $v['school'])
								->setCellValue('L'.$num, $v['subject'])
								->setCellValue('M'.$num, $v['education'])
								->setCellValue('N'.$num, $v['computer'])
								->setCellValue('O'.$num, $v['work_year'])
								->setCellValue('P'.$num, $v['target'])
								->setCellValue('Q'.$num, $v['contacts_name'])
								->setCellValue('R'.$num, $v['contacts_relation'])
								->setCellValue('S'.$num, $v['contacts_phone']);

					// 设置单元格左对齐
					$objPHPExcel->getActiveSheet()
								->getStyle('A'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('B'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('C'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('D'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('E'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('F'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('G'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('H'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('I'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('J'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('K'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('L'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('M'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('N'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('O'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('P'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('Q'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('R'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					$objPHPExcel->getActiveSheet()
								->getStyle('S'.$num)
								->getAlignment()
								->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
				 }
				break;
			case 6:
				$str=[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z];
				// 获取数组键名组成新数组
				$key = array_keys($list['0']);
				for ($i=0; $i < count($list['0']); $i++) { 
					// 设置Excel单元格标题
					$objPHPExcel->setActiveSheetIndex(0)->setCellValue($str[$i].'1', $key[$i]);
					// 设置单元格宽度
					$objPHPExcel->getActiveSheet()->getColumnDimension($str[$i])->setWidth(20);
					// 设置标题单元格左对齐
					$objPHPExcel->getActiveSheet()->getStyle($str[$i].'1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
				}

				// 有几条数据也就是有几行 
				for ($i=0; $i < count($list); $i++) {
					// 数组长度决定有几列
					for ($j=0; $j < count($list['0']); $j++) { 
						$objPHPExcel->setActiveSheetIndex(0)->setCellValue($str[$j].($i+2), array_values($list[$i])[$j]);
						// 设置内容单元格左对齐
						$objPHPExcel->getActiveSheet()->getStyle($str[$j].($i+2))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
					}
				}
				break;
		}

		// 导入输出类
		import("Org.Util.PHPExcel.IOFactory");	

		// 浏览器响应头说明文件类型下载
		header("Content-Type: application/vnd.ms-excel");
		header("Content-Disposition: attachment;filename=".$name." ".date("Y-m-d",time()).".xlsx");
		header("Cache-Control: max-age=0");

		// 输出文件xlsx
		$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter->save('php://output');
		exit;
	}
	

	//短信验证
	function test($to,$param){
		//载入ucpass类
		import('Vendor.lib.Ucpaas');

		//初始化必填
		$options['accountsid']='5434736dacc81112c54fe4690f3918db';
		$options['token']='5533ad03bfed6a6a8bbab65f106c4c31';

		//初始化 $options必填
		$ucpass = new Ucpaas($options);

		//开发者账号信息查询默认为json或xml
		echo $ucpass->getDevinfo('json');

		//申请client账号
		//$appId = "xxxx";
		//$clientType = "0";
		//$charge = "0";
		//$friendlyName = '';
		//$mobile = "18612345678";

		//echo $ucpass->applyClient($appId, $clientType, $charge, $friendlyName, $mobile);

		//删除client账号
		//$appId = "xxxx";
		//$clientNumber='xxxxx';

		//echo $ucpass->releaseClient($clientNumber,$appId);

		//删除client账号
		//$appId = "xxxx";
		//$start = "0";
		//$limit = "100";
		//
		//echo $ucpass->getClientList($appId,$start,$limit);

		//以Client账号方式查询Client信息
		//$appId = "xxxx";
		//$clientNumber='xxxx';
		//
		//echo $ucpass->getClientInfo($appId,$clientNumber);

		//以手机号码方式查询Client信息
		//$appId = "xxxx";
		//$mobile = "18612345678";

		//echo $ucpass->getClientInfoByMobile($appId,$mobile);

		//应用话单下载,通过HTTPS POST方式提交请求，云之讯融合通讯开放平台收到请求后，返回应用话单下载地址及文件下载检验码。
		//day 代表前一天的数据（从00:00 – 23:59）；week代表前一周的数据(周一 到周日)；month表示上一个月的数据（上个月表示当前月减1，如果今天是4月10号，则查询结果是3月份的数据）
		//$appId = "xxxx";
		//$date = "day";

		//echo $ucpass->getBillList($appId,$date);

		//Client充值,通过HTTPS POST方式提交充值请求，云之讯融合通讯开放平台收到请求后，返回Client充值结果。
		//$appId = "xxxx";
		//$clientNumber='xxxx';
		//$clientType = "0";
		//$charge = "0";

		//echo $ucpass->chargeClient($appId,$clientNumber,$clientType,$charge);

		//双向回拨,云之讯融合通讯开放平台收到请求后，将向两个电话终端发起呼叫，双方接通电话后进行通话。
		//$appId = "xxxx";
		//$fromClient = "xxxx";
		//$to = "18612345678";
		//$fromSerNum = '';
		//$toSerNum = '';

		//echo $ucpass->callBack($appId,$fromClient,$to);

		//语音验证码,云之讯融合通讯开放平台收到请求后，向对象电话终端发起呼叫，接通电话后将播放指定语音验证码序列
		//$appId = "ee2ff8422ee6452a90ebb0665582f1f1";
		//$verifyCode = "1113";
		//$to = "18895305100";

		//echo $ucpass->voiceCode($appId,$verifyCode,$to);

		//短信验证码（模板短信）,默认以65个汉字（同65个英文）为一条（可容纳字数受您应用名称占用字符影响），超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。
		$appId = "e0fd9976a2434d71b5930d300b70b05a";
		$to = $to;
		$templateId = "40602";
		$param=$param;

		echo $ucpass->templateSMS($appId,$to,$templateId,$param);
	}
	
 ?>